import { request } from '@/utils/request';

import { Info, MenuItem, ResourceItem, TableParams, TableRes, UserGroupItem, UserItem } from './model';

/**
 * 动态列表查询
 * @param params
 * @returns
 */
export function roleSelectPage(params: TableParams) {
  return request.get<TableRes>({
    url: '/platform/roleSelectsPage',
    params,
  });
}

/**
 * 获取角色详情
 * @param params
 * @returns
 */
export function getRoleInfo(params: { id: string }) {
  return request.get<Info>({
    url: `/platform/getRoleSU`,
    params,
  });
}

/**
 * 查询角色的菜单
 * @param params
 * @returns
 */
export function roleSelectMenu(params: { roleId: string }) {
  return request.get<MenuItem[]>({
    url: `/platform/roleSelectMenus`,
    params,
  });
}

/**
 * 查询角色已绑定的用户
 * @param params
 * @returns
 */
export function roleSelectResources(params: { roleId: string }) {
  return request.get<ResourceItem[]>({
    url: `/platform/roleSelectResources`,
    params,
  });
}

/**
 * 当前角色拥有的用户组
 * @param params
 * @returns
 */
export function roleSelectUserGroup(params: { roleId: string }) {
  return request.get<UserGroupItem[]>({
    url: `/platform/roleSelectJobs`,
    params,
  });
}

/**
 * 查询角色已绑定的用户
 * @param params
 * @returns
 */
export function roleSelectUsers(params: { roleId: string }) {
  return request.get<UserItem[]>({
    url: `/platform/roleSelectUsers`,
    params,
  });
}

/**
 * 查询菜单的树结构目录
 * @returns
 */
export function menuSelectTree() {
  return request.get<MenuItem[]>({
    url: `/platform/menuSelectsTree`,
  });
}

/**
 * 更新角色要绑定的菜单
 * @returns
 */
export function roleUpdateMenu(params: { id: string | number; ids: (string | number)[] }) {
  return request.post({
    url: `/platform/roleUpdateMenus`,
    data: params,
  });
}

/**
 * 应用下拉选择
 * @param params
 * @returns
 */
export function applicationSelect() {
  return request.get({
    url: `/platform/applicationSelects`,
    method: 'get',
  });
}
/**
 * 获取资源列表
 * @param params
 * @returns
 */
export function resourceSelectNames(params: { aplId: string; businessType?: string; name?: string }) {
  return request.get({
    url: `/platform/resourceSelectNames`,
    params,
  });
}

/**
 * 更新用户选择资源
 * @param params
 * @returns
 */
export function roleUpdateResources(params: { id: string | number; ids: (string | number)[] }) {
  return request.post({
    url: `/platform/roleUpdateResources`,
    data: params,
  });
}

/**
 * 获取用户组列表
 * @param params
 * @returns
 */
export function jobSelectNames(params?: { name: string }) {
  return request.get({
    url: `/platform/jobSelectNames`,
    params,
  });
}

/**
 * 更新用户组
 * @param params
 * @returns
 */
export function roleUpdateJobs(params: { id: string | number; ids: (string | number)[] }) {
  return request.post({
    url: `/platform/roleUpdateJobs`,
    data: params,
  });
}
/**
 * 按名字获取用户列表
 * @param params
 * @returns
 */
export function userSelectNames(params?: { name: string }) {
  return request.get({
    url: `/platform/userSelectNames`,
    params,
  });
}

/**
 * 更新绑定用户
 * @param params
 * @returns
 */
export function roleUpdateUsers(params: { id: string; ids: string[] }) {
  return request.post({
    url: `/platform/roleUpdateUsers`,
    data: params,
  });
}
